package user

import (
	"context"
	"errors"
	"hzjt-oam/admin/internal/svc"
	"hzjt-oam/admin/internal/types"
	"hzjt-oam/rpc/sys/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserListLogic) UserList(req *types.ListUserReq) (resp *types.ListUserResp, err error) {
	user, err := l.svcCtx.UserSrv.SearchSysUser(l.ctx, &pb.SearchSysUserReq{
		Page:     req.Current,
		PageSize: req.PageSize,
	})
	if err != nil {
		return nil, errors.New("获取用户列表失败")
	}

	return &types.ListUserResp{
		Message:  "成功",
		Current:  req.Current,
		Data:     user.GetSysUser(),
		PageSize: req.PageSize,
		Total:    int64(len(user.SysUser)),
	}, nil
}
